<?php
/**
 * 自动打包功能模块
 * @author Administrator
 *
 */
class PackageModel extends Model{
	 function getArea(){
	 	$sql = "select id,code,code_num,country_en,country_cn from area";
	 	return $this->db->getRecords($sql);
	 }
	 //获取发行国家
	 function getChannelCountry(){
	 	$sql = "select id,country_cn,country_num from channel_country order by id";
	 	return $this->db->getRecords($sql);
	 }
	 
	 function getChannelCountryByNum($country_num){
	 	$sql = "select id,country_cn,country_num,market_lang,market_name,market_domain,rsync_sh_path from channel_country where country_num='{$country_num}' limit 1";
	 	return $this->db->getRecord($sql);
	 }
	 
	 //检查渠道号是否存在
	 function checkChannel($channel_id){
	 	$sql = "select channel_id from channel_list where channel_id='{$channel_id}'";
	 	return $this->db->getString($sql);
	 }
	 
	 //获取国家详细信息
	 function getAreaInfo($area_id=0,$code_num=''){
	 	if(!empty($area_id)){
	 		$add_sql = " and id={$area_id}";
	 	}elseif(!empty($code_num)){
	 		$add_sql = " and code_num='{$code_num}'";
	 	}
	 	$sql = "select id,code,code_num,country_en,country_cn from area where 1=1 {$add_sql} limit 1";
	 	return $this->db->getRecord($sql);
	 }
	 //查询渠道号的信息
	 function getChannelListInfo($channel_id){
	 	$sql = "select * from channel_list where channel_id='{$channel_id}'";
	 	return $this->db->getRecord($sql);
	 }
	 function getChannelUrlInfo($channel_id){
	 	$sql = "select * from channel_url where channel_id='{$channel_id}'";
	 	return $this->db->getRecords($sql);
	 }
	 //根据渠道号和内部包名来判断运营地址是否存在
	 function checkChannelExists($channel_id,$package_name){
	 	$package_name = $this->db->escape_string($package_name);
	 	$sql = "select channel_id from channel_url where channel_id='{$channel_id}' and package_name='{$package_name}'";
	 	return $this->db->getString($sql);
	 }
	 
	 function getUserRole($user_id){
	 	$sql = "select a.user_name,a.is_admin,ar.role_name from admin as a left join admin_role as ar on a.role_id = ar.role_id where a.user_id={$user_id}";
	 	return $this->db->getRecord($sql);
	 }
	 
}